<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>notation</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade><blockquote>
<center>
<h2><a name = "tag_006">&nbsp;</a>File Format Notation</h2>
</center>
<xref type="1" name="filefmt"></xref>
The
<b>STDIN</b>,
<b>STDOUT</b>,
<b>STDERR</b>,
<b>INPUT FILES</b>
and
<b>OUTPUT FILES</b>
sections of the utility descriptions use
a syntax to describe the
data organisation within the files,
when that organisation is not otherwise obvious.
The syntax is similar to that used by the <b>XSH</b> specification
<i><a href="../xsh/printf.html">printf()</a></i>
function, as described in this chapter.
When used in
<b>STDIN</b>
or
<b>INPUT FILES</b>
sections of the utility descriptions,
this syntax describes the format that could have been used to write the
text to be read, not a format that could be used by the 
<i><a href="../xsh/scanf.html">scanf()</a></i>
function to read the input file.
<p>
The description of an individual record is as follows:
<code>
<pre>
"&lt;<i>format</i>&gt;", <b>[</b>&lt;<i>arg1</i>&gt;, &lt;<i>arg2</i>&gt;,..., &lt;<i>argn</i>&gt;<b>]
</b></code>
</pre>
<p>
The
<i>format</i>
is a character string that contains three types of
objects defined below:
<dl compact>

<dt><i>characters</i><dd><br>
Characters that are not
<i>escape sequences</i>
or
as described below, are copied to the output.

<dt><i>escape sequences</i><dd><br>
Represent non-graphic characters.

<dt><i>conversion specifications</i><dd><br>
Specifies the output format of each argument.
(See below.)

</dl>
<p>
The following characters have the following special meaning in the
format string:
<dl compact>

<dt>" " <dd>(An empty character position.)
One or more
blank
characters.

<dt><img src="../images/delta.gif" border=0> <dd>Exactly one space character.
</dl>
<p>
The notation for spaces allows some flexibility for application output.
Note that an empty character position in
<i>format</i>
represents one or more
blank
characters on the output (not
which can include
newline characters).
Therefore, another utility that reads that output as its input
must be prepared to parse
the data using
<i><a href="../xsh/scanf.html">scanf()</a></i>,
<i><a href="../xcu/awk.html">awk</a></i>,
and so forth.
<p>
The following table lists escape sequences and 
associated actions on display devices capable of the action.
<pre>
<table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Escape Sequence</b>
<th align=center><b>Represents Character</b>
<th align=center><b>Terminal Action</b>
<tr valign=top><td align=center><b>\\</b>
<td align=left>backslash
<td align=left>None.
<tr valign=top><td align=center><b>\a</b>
<td align=left>alert
<td align=left> Attempts to alert the user through audible or visible notification. 
<tr valign=top><td align=center><b>\b</b>
<td align=left>backspace
<td align=left> Moves the printing position to one column before the current position, unless the current position is the start of a line. 
<tr valign=top><td align=center><b>\f</b>
<td align=left>form-feed
<td align=left> Moves the printing position to the initial printing position of the next logical page. 
<tr valign=top><td align=center><b>\n</b>
<td align=left>newline
<td align=left> Moves the printing position to the start of the next line. 
<tr valign=top><td align=center><b>\r</b>
<td align=left>carriage-return
<td align=left> Moves the printing position to the start of the current line. 
<tr valign=top><td align=center><b>\t</b>
<td align=left>tab
<td align=left> Moves the printing position to the next tab position on the current line. If there are no more tab positions left on the line, the behaviour is undefined. 
<tr valign=top><td align=center><b>\v</b>
<td align=left>vertical-tab
<td align=left> Moves the printing position to the start of the next vertical tab position. If there are no more vertical tab positions left on the page, the behaviour is undefined. 
</table>
</pre>
<h6 align=center><xref table="Escape Sequences and Associated Actions"><a name="tagt_6">&nbsp;</a></xref>Table: Escape Sequences and Associated Actions</h6>
<xref type="7" name="escseq"></xref>
<p>
Each conversion specification is introduced by
the percent-sign character (%).
After the character %, the following appear in sequence:
<dl compact>

<dt><i>flags</i><dd>Zero or more
<i>flags</i>,
in any order, that modify the meaning of the conversion specification.

<dt><i>field&nbsp;width</i><dd>An optional string of decimal digits to
specify a minimum <i>field width</i>.
For an output field,
if the converted value has fewer
bytes than the field width,
it is padded on the left
(or right, if the left-adjustment
flag (-), described below, has been given to the field width).

<dt><i>precision</i><dd>Gives the minimum number of digits to appear
for the d, o, i, u, x or X conversions
(the field is padded with leading zeros), the number of
digits to appear after the radix character for the
e and f conversions, the maximum number of significant digits for the
g conversion; or the maximum number of
bytes to be written from a string in s conversion.
The precision takes the form of a period (.) followed by a
decimal digit string; a null digit string is treated as zero.

<dt><i>conversion characters</i><dd><br>
A conversion character (see below) that indicates the type of conversion
to be applied.

</dl>
<p>
The <i>flag</i> characters and their meanings are:
<dl compact>

<dt>-<dd>The result of the conversion is left-justified within the field.

<dt>+<dd>The result of a signed conversion
always begins with a sign (+ or -).

<dt>&lt;space&gt;<dd>If the first character of a signed conversion is not a sign, a
space character
is prefixed to the result.
This means that if the
space character and +
flags both appear, the
space character
flag is ignored.


<dt>#<dd>The value is to be converted to an alternative form.
For
c,
d,
i,
u
and
s
conversions, the
behaviour is undefined.
For o conversion, it increases the precision to force the
first digit of the result to be a zero.
For x or X conversion, a non-zero result
has 0x or 0X prefixed to it,
respectively.
For e, E, f,
g and G conversions,
the result always contains a radix character,
even if no digits
follow the radix character.
For g and G conversions,
trailing zeros are not removed from the result as they usually are.

<dt>0<dd>For
d,
i,
o,
u,
x,
X,
e,
E,
f,
g
and
G
conversions, leading zeros (following any indication of sign or base)
are used to pad to the field width; no space padding is performed.
If the
0
and
-
flags both appear, the
0
flag is ignored.
For
d,
i,
o,
u,
x
and
X
conversions, if a precision is specified, the
0
flag is ignored.
For other conversions, the behaviour is undefined.

</dl>
<p>
Each conversion character results in fetching zero or more arguments.
The results are undefined if there are insufficient arguments for the format.
If the format is exhausted while arguments remain, the excess
arguments are ignored.
<p>
The
<i>conversion characters</i>
and their meanings are:
<dl compact>

<dt>d,i,o,u,x,X<dd>The integer
argument
is written as signed decimal (d or i),
unsigned octal (o), unsigned decimal (u), or unsigned
hexadecimal notation (x and X).
The
d
and
i
specifiers convert to signed decimal in the style
<b>[</b>-<b>]</b><i>dddd</i>.
The x conversion uses the numbers and letters
0123456789abcdef and
the X conversion uses the numbers and letters
0123456789ABCDEF.
The <i>precision</i> component of the argument
specifies the minimum number of digits to appear.
If the value being converted can be represented in fewer digits
than the specified minimum, it is expanded with leading zeros.
The default precision is 1.
The result of converting a zero value with a precision of 0
is no characters.
If both the field width and precision are omitted,
the implementation may precede, follow or precede and follow
numeric arguments
of types
d,
i
and
u
with
blank characters;
arguments of type
o
(octal) may be preceded with leading zeros.

The treatment of integers and spaces is different from the
<i><a href="../xsh/printf.html">printf()</a></i>
function in that they can be surrounded with
blank characters.
This was done so that, given a format such as:
<pre>
<dl compact><dt> <dd>
<tt>"%d\n"</tt>, &lt;<i>foo</i>&gt;
</dl>
</pre>
the implementation could use a
<i><a href="../xsh/printf.html">printf()</a></i>
call such as:
<code>
<pre>
printf("%6d\n", foo);
</code>
</pre>
and still conform.
This notation is thus somewhat like
<i><a href="../xsh/scanf.html">scanf()</a></i>
in addition to
<i><a href="../xsh/printf.html">printf()</a></i>.
<p>
<dt>f<dd>The floating point number argument is written in decimal notation in
the style <b>[</b>-<b>]</b><i>ddd</i>.<i>ddd</i>,
where the number of digits after the radix character
(shown here as a decimal point) is equal to
the <i>precision</i> specification.
The LC_NUMERIC locale category
determines the radix character to use in this format.
If the <i>precision</i> is omitted from
the argument, six digits are written after the radix character;
if the <i>precision</i> is explicitly 0,
no radix character appears.
<p>
<dt>e,E<dd>The floating point number argument is written in the
style <b>[</b>-<b>]</b><i>d</i>.<i>ddd</i>e&plusmn;2dd
(the symbol &plumn;
indicates either a plus or minus sign),
where there is one digit before the radix character
(shown here as a decimal point)
and the number of digits after it is equal to the precision.
The LC_NUMERIC locale category
determines the radix character to use in this format.
When the precision is missing, six digits are 
written after the radix character; if the
precision is 0, no radix character appears.
The E conversion character
produces a number with E
instead of e introducing the exponent.
The exponent always contains at least two digits.
However, if the value to be written
requires an exponent greater than two digits,
additional exponent
digits are written as necessary.
<p>
<dt>g,G<dd>The floating point number argument is written in style f
or e (or in style E in the case of a G
conversion character), with the precision specifying the number
of significant digits.
The style used depends on the value converted:
style g is used only if the exponent resulting
from the conversion is less
than -4 or greater than or equal to the precision.
Trailing zeros are removed from the result.
A radix character appears only if it is followed by a digit.
<p>
<dt>c<dd>The integer argument is converted to an
<b>unsigned char</b>
and the resulting byte is written.
<p>
<dt>s<dd>The argument is taken to be a string
and bytes from
the string are written until the
end of the string
or the number of bytes indicated by the <i>precision</i>
specification of the argument is reached.
If the precision is omitted from
the argument,
it is taken to be infinite,
so all bytes up to the end of the string are written.
<p>
<dt>%<dd>Write a % character; no argument is converted.
<p>
</dl>
<p>
In no case does a non-existent or insufficient
<i>field width</i>
cause truncation
of a field; if the result of a conversion is wider than the field width,
the field is simply expanded to contain the conversion result.
The term
<i>field width</i>
should not be confused with the term
<i>precision</i>
used in the description of %s.
<p>
One difference from the C function
<i><a href="../xsh/printf.html">printf()</a></i>
is that the l and h
conversion characters are not used.
As expressed by the <b>XCU</b> specification, there is no
differentiation between decimal values for type
<b>int</b>,
type 
<b>long</b>
or type 
<b>short</b>.
The specifications %d or %i
should be interpreted as an arbitrary length
sequence of digits.
Also, no distinction is made between single precision and double
precision numbers
(<b>float</b>
or
<b>double</b>
in C).
These are simply referred to as floating point numbers.
<p>
Many of the output descriptions in the <b>XCU</b> specification use the term
such as:
<pre>
<dl compact><dt> <dd>
<tt>"%s"</tt>, &lt;<i>input line</i>&gt;
</dl>
</pre>
<p>
Since the definition of
<i>line</i>
includes the trailing
newline
character already, there is no need to include a
\n
in the format; a double
newline character
would otherwise result.
<p>
<h5><a name = "tag_006_000_000_001">&nbsp;</a>Examples</h5>
To represent the output of a program that
prints a date and time in the form Sunday, July 3, 10:02,
where
&lt;<i>weekday</i>&gt;
and
&lt;<i>month</i>&gt;
are strings:
<p>
<dl compact><dt> <dd>
<p>
<tt>"%s,<img src="../images/delta.gif" border=0>%s<img src="../images/delta.gif" border=0>%d,<img src="../images/delta.gif" border=0>%d:%.2d\n"</tt>, &lt;<i>weekday</i>&gt;,
&lt;<i>month</i>&gt;,
&lt;<i>day</i>&gt;,
&lt;<i>hour</i>&gt;,
&lt;<i>min</i>&gt;
</p>
</dl>
</p>
<p>
To show <sub><img src="../images/pi.gif" border=0></sub>  written to 5 decimal places:
<pre>
<dl compact><dt> <dd>
<tt>"pi = %.5f\n"</tt>, &lt;<i>value of <sub><img src="../images/pi.gif" border=0></sub></i>&gt;
</dl>
</pre>
<p>
To show an input file format consisting of five colon-separated fields:
<p>
<dl compact><dt> <dd>
<tt>"%s:%s:%s:%s:%s\n"</tt>, &lt;<i>arg1</i>&gt;,
&lt;<i>arg2</i>&gt;,
&lt;<i>arg3</i>&gt;,
&lt;<i>arg4</i>&gt;,
&lt;<i>arg5</i>&gt;
</dl>
</p>
</blockquote>
<hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
